Fix return from xenbus_scanf: returns number scanned, not 0!
authorcl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Tue, 26 Jul 2005 17:04:33 +0000 (17:04 +0000)
committercl349@firebug.cl.cam.ac.uk <cl349@firebug.cl.cam.ac.uk>
Tue, 26 Jul 2005 17:04:33 +0000 (17:04 +0000)
Fix xenbus_write args in xenbus_printf
Signed-off-by: Rusty Russel <rusty@rustcorp.com.au>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_probe.c
linux-2.6-xen-sparse/drivers/xen/xenbus/xenbus_xs.c
linux-2.6-xen-sparse/include/asm-xen/xenbus.h

index 8ff7774df5ac8ffcb5516d5e002170706754ed13..f1c9360ad719e27a54cec070c167db34c1ef03c2 100644 (file)
@@ -1,6 +1,5 @@
 /******************************************************************************
  * Talks to Xen Store to figure out what devices we have.
- * Currently experiment code, but when I grow up I'll be a bus driver!
  *
  * Copyright (C) 2005 Rusty Russell, IBM Corporation
  * Copyright (C) 2005 Mike Wray, Hewlett-Packard
 #include <stdarg.h>
 #include "xenbus_comms.h"
 
-/* Name of field containing device type. */
-#define XENBUS_DEVICE_TYPE "type"
-
-static int xs_init_done = 0;
-
 #define streq(a, b) (strcmp((a), (b)) == 0)
 
 /* If something in array of ids matches this device, return it. */
@@ -83,18 +77,13 @@ static int xenbus_dev_probe(struct device *_dev)
        struct xenbus_driver *drv = to_xenbus_driver(_dev->driver);
        const struct xenbus_device_id *id;
 
-       printk("Probing device '%s'\n", _dev->bus_id);
-       if (!drv->probe) {
-               printk("'%s' no probefn\n", _dev->bus_id);
+       if (!drv->probe)
                return -ENODEV;
-       }
 
        id = match_device(drv->ids, dev);
-       if (!id) {
-               printk("'%s' no id match\n", _dev->bus_id);
+       if (!id)
                return -ENODEV;
-       }
-       printk("probing '%s' fn %p\n", _dev->bus_id, drv->probe);
+
        return drv->probe(dev, id);
 }
 
@@ -125,94 +114,80 @@ void xenbus_unregister_driver(struct xenbus_driver *drv)
 }
 
 /* devices/<typename>/<name> */
-static int xenbus_probe_device(const char *typename, const char *name)
+static int xenbus_probe_device(const char *dirpath, const char *devicetype,
+                              const char *name)
 {
        int err;
        struct xenbus_device *xendev;
        unsigned int stringlen;
 
-       pr_debug("> dir=%s name=%s\n", typename, name);
-
        /* FIXME: This could be a rescan. Don't re-register existing devices. */
 
        /* Nodename: /device/<typename>/<name>/ */
-       stringlen = strlen("device") + strlen(typename) + strlen(name) + 3;
+       stringlen = strlen(dirpath) + strlen(devicetype) + strlen(name) + 3;
        /* Typename */
-       stringlen += strlen(typename) + 1;
-
+       stringlen += strlen(devicetype) + 1;
        xendev = kmalloc(sizeof(*xendev) + stringlen, GFP_KERNEL);
        if (!xendev)
                return -ENOMEM;
-
        memset(xendev, 0, sizeof(*xendev));
+
        /* Copy the strings into the extra space. */
        xendev->nodename = (char *)(xendev + 1);
-       sprintf(xendev->nodename, "%s/%s/%s", "device", typename, name);
+       sprintf(xendev->nodename, "%s/%s/%s", dirpath, devicetype, name);
        xendev->devicetype = xendev->nodename + strlen(xendev->nodename) + 1;
-       strcpy(xendev->devicetype, typename);
+       strcpy(xendev->devicetype, devicetype);
 
        /* FIXME: look for "subtype" field. */
-       snprintf(xendev->dev.bus_id, BUS_ID_SIZE, "%s-%s", typename, name);
+       snprintf(xendev->dev.bus_id, BUS_ID_SIZE, "%s-%s", devicetype, name);
        xendev->dev.bus = &xenbus_type;
 
        /* Register with generic device framework. */
-       printk("XENBUS: Registering device %s\n", xendev->dev.bus_id);
        err = device_register(&xendev->dev);
        if (err) {
                printk("XENBUS: Registering device %s: error %i\n",
                       xendev->dev.bus_id, err);
                kfree(xendev);
        }
-
-       pr_debug("< err=%i\n", err);
        return err;
 }
 
-/* /device/<typename> */
-static int xenbus_probe_device_type(const char *typename)
+static int xenbus_probe_device_type(const char *dirpath, const char *typename)
 {
        int err = 0;
        char **dir;
        unsigned int dir_n = 0;
        int i;
 
-       dir = xenbus_directory("device", typename, &dir_n);
-       printk("dir %s has %u entries\n", typename, dir_n);
-       if (IS_ERR(dir)) {
-               printk("dir %s returned %li\n", typename, PTR_ERR(dir));
+       dir = xenbus_directory(dirpath, typename, &dir_n);
+       if (IS_ERR(dir))
                return PTR_ERR(dir);
-       }
 
        for (i = 0; i < dir_n; i++) {
-               printk("Probing %s/%s\n", dir[i], typename);
-               err = xenbus_probe_device(dir[i], typename);
+               err = xenbus_probe_device(dirpath, typename, dir[i]);
                if (err)
                        break;
        }
        kfree(dir);
-       pr_debug("< err=%i\n", err);
        return err;
 }
 
-static int xenbus_probe_devices(void)
+static int xenbus_probe_devices(const char *path)
 {
        int err = 0;
        char **dir;
        unsigned int i, dir_n;
 
        down(&xenbus_lock);
-       dir = xenbus_directory("device", "", &dir_n);
+       dir = xenbus_directory(path, "", &dir_n);
        if (IS_ERR(dir)) {
                err = PTR_ERR(dir);
                goto unlock;
        }
        for (i = 0; i < dir_n; i++) {
-               err = xenbus_probe_device_type(dir[i]);
-               if (err) {
-                       printk("xenbus: error %i probing device %s\n",
-                              -err, dir[i]);
+               err = xenbus_probe_device_type(path, dir[i]);
+               if (err)
                        break;
-               }
        }
        kfree(dir);
 unlock:
@@ -225,25 +200,18 @@ int do_xenbus_probe(void *unused)
 {
        int err = 0;
 
-       printk("%s> xs_init_done=%d\n", __FUNCTION__, xs_init_done);
-       if (xs_init_done)
-               goto exit;
        /* Initialize xenstore comms unless already done. */
        printk("store_evtchn = %i\n", xen_start_info.store_evtchn);
        err = xs_init();
        if (err) {
                printk("XENBUS: Error initializing xenstore comms:"
                       " %i\n", err);
-               goto exit;
+               return err;
        }
-       xs_init_done = 1;
 
        /* Enumerate devices in xenstore. */
-       xenbus_probe_devices();
-
-exit:
-       printk("%s< err=%d\n", __FUNCTION__, err);
-       return err;
+       xenbus_probe_devices("device");
+       return 0;
 }
 
 static int __init xenbus_probe_init(void)
index 9e1f3b721394f98dacaada462a9982d5cc5690c0..3c1f159540517b69c392af62dec14124a742bad8 100644 (file)
@@ -347,8 +347,7 @@ int xenbus_printf(const char *dir, const char *node, const char *fmt, ...)
        va_end(ap);
 
        BUG_ON(ret > sizeof(buffer)-1);
-
-       return xenbus_write(dir, node, buffer, ret+1);
+       return xenbus_write(dir, node, buffer, O_CREAT);
 }
 
 /* Takes tuples of names, scanf-style args, and void **, NULL terminated. */
index 94bb5da9834a94a65f8a4c823cb2a0cdfa648bb8..217425120477e3b29809866868011bc4bba563ac 100644 (file)
@@ -59,8 +59,7 @@ struct xenbus_driver {
        const struct xenbus_device_id *ids;
        int  (*probe)    (struct xenbus_device * dev,
                          const struct xenbus_device_id * id);
-        int  (*remove)   (struct xenbus_device * dev);
-
+       int  (*remove)   (struct xenbus_device * dev);
        struct device_driver driver;
 };